﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ModelLibrary;

namespace WebC
{
    public partial class base_brand : clsBaseForm
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Ajax.Utility.RegisterTypeForAjax(typeof(base_brand));
            if (!IsPostBack)
            {
                loadInfo();
            }
        }

        [Ajax.AjaxMethod]
        public bool deleFile(string sFileName)
        {
            return deleteFileByPath(sFileName);
        }

        #region 载入信息

        public void loadInfo()
        {
            BaseInfo baseinfo = null;
            string sModelName = "";
            DataTable dt = null;
            try
            {
                baseinfo = new BaseInfo();
                if (m_Id == 0)
                {
                    if (!checkModelRightById(533, ref sModelName, (clsBaseLib)baseinfo))
                    {
                        errorUrl(string.Format("你没有“{0}”的权限,请与管理员联系！", sModelName));
                        return;
                    }
                }
                else
                {
                    if (Convert.ToInt32(Request["noedit"]) == 1)
                    {
                        if (!checkModelRightById(532, ref sModelName, (clsBaseLib)baseinfo))
                        {
                            errorUrl(sModelName);
                            return;
                        }
                    }
                    else
                    {
                        if (!checkModelRightById(534, ref sModelName, (clsBaseLib)baseinfo))
                        {
                            errorUrl(sModelName);
                            return;
                        }
                    }
                    dt = baseinfo.getBrandInfoById(m_Id);

                }
                sModelFullName = sModelName;
            }
            catch (Exception e)
            {
                errorUrl(Convert.ToString(e));
            }
            finally
            {
                if (baseinfo != null)
                {
                    baseinfo.Dispose();
                }
            }
            if (m_Id > 0)
            {
                if (dt.Rows.Count == 1)
                {
                    ddlIsImport.SelectedValue = Convert.ToString(dt.Rows[0]["isimport"]);
                    txtBrandName.Text = Convert.ToString(dt.Rows[0]["brandname"]);
                    txtBrandCode.Text = Convert.ToString(dt.Rows[0]["brandcode"]);
                    txtBrandDesc.Text = Convert.ToString(dt.Rows[0]["branddesc"]);
                }
            }
        }


        #endregion

        int m_Id
        {
            get
            {
                return Convert.ToInt32(Request["id"]);
            }
        }

        #region 保存信息

        [Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)]
        public bool saveData(int iBrandId, string sName, string sCode, int iIsImport, string sDesc)
        {
            BaseInfo baseinfo = null;
            bool bResult = false;
            sName = sName.Replace("'", "''");
            sCode = sCode.Replace("'", "''");
            sDesc = sDesc.Replace("'", "''");
            try
            {
                baseinfo = new BaseInfo();
                bResult = baseinfo.setBrandInfo(iBrandId, sName, sCode, iIsImport, sDesc);
            }
            catch
            {
                bResult = false;
            }
            finally
            {
                if (baseinfo != null)
                {
                    baseinfo.Dispose();
                }
            }
            return bResult;
        }

        #endregion
    }
}